******************
*** 2_PART TWO ***
******************
cd "~"
use 1_p2_subgroups.dta, clear

foreach var of varlist env_im env_hom env_un im_hom im_un hom_un cc_env cc_im cc_hom cc_un {
	gen `var'_val = .
	replace `var'_val = abs(`var')
}

// Constraint
egen rm = rowmiss(env_im_val env_hom_val env_un_val im_hom_val im_un_val hom_un_val)
egen pcA = rowtotal(env_im_val env_hom_val env_un_val im_hom_val im_un_val hom_un_val) if rm == 0
gen BSA = pcA*(2/(4*(4-1)))
lab var BSA "Constraint within belief system {it:A}"
drop rm

egen rm = rowmiss(env_im_val env_hom_val env_un_val im_hom_val im_un_val hom_un_val cc_env_val cc_im_val cc_hom_val cc_un_val)
egen pcB = rowtotal(env_im_val env_hom_val env_un_val im_hom_val im_un_val hom_un_val cc_env_val cc_im_val cc_hom_val cc_un_val) if rm == 0
gen BSB = pcB*(2/(5*(5-1)))
lab var BSB "Constraint within belief system {it:B}"
drop rm

// Constraint (gener4)
foreach var of varlist *_gener4 {
	gen `var'_val = .
	replace `var'_val = abs(`var')
}

egen rm = rowmiss(env_im_gener4_val env_hom_gener4_val env_un_gener4_val im_hom_gener4_val im_un_gener4_val hom_un_gener4_val)
egen pcA_gener4 = rowtotal(env_im_gener4_val env_hom_gener4_val env_un_gener4_val im_hom_gener4_val im_un_gener4_val hom_un_gener4_val) if rm == 0
gen BSA_gener4 = pcA_gener4*(2/(4*(4-1)))
lab var BSA_gener4 "Constraint within belief system {it:A}"
drop rm

egen rm = rowmiss(*_gener4_val)
egen pcB_gener4 = rowtotal(*_gener4_val) if rm == 0
gen BSB_gener4 = pcB_gener4*(2/(5*(5-1)))
lab var BSB_gener4 "Constraint within belief system {it:B}"
drop rm

// Constraint (gener3)
foreach var of varlist *_gener3 {
	gen `var'_val = .
	replace `var'_val = abs(`var')
}

egen rm = rowmiss(env_im_gener3_val env_hom_gener3_val env_un_gener3_val im_hom_gener3_val im_un_gener3_val hom_un_gener3_val)
egen pcA_gener3 = rowtotal(env_im_gener3_val env_hom_gener3_val env_un_gener3_val im_hom_gener3_val im_un_gener3_val hom_un_gener3_val) if rm == 0
gen BSA_gener3 = pcA_gener3*(2/(4*(4-1)))
lab var BSA_gener3 "Constraint within belief system {it:A}"
drop rm

egen rm = rowmiss(*_gener3_val)
egen pcB_gener3 = rowtotal(*_gener3_val) if rm == 0
gen BSB_gener3 = pcB_gener3*(2/(5*(5-1)))
lab var BSB_gener3 "Constraint within belief system {it:B}"
drop rm

save 2_p2_subgroups.dta, replace

// Belief System A (2012-2022; Figure 4)

mixed BSA c.year ib3.leftright c.year#ib3.leftright ///
	ib2.gener5 c.year#ib2.gener5 ///
	ib0.sex c.year#ib0.sex ///
	ib0.partisan c.year#ib0.partisan ///
	ib0.intr c.year#ib0.intr ///
if year >= 2012 || _all: R.land || _all: R.year, var

** left-right
margins, dydx(year) over(leftright)
marginsplot, plotop(msymbol(Oh) msize(medlarge) mc(edkblue) mlwidth(medium) lc(edkblue*.3) lwidth(thin) lp(longdash)) ciopts(lc(edkblue*.5) lwidth(medthin)) ///
	xla(1 "Left" 2 `" "Cent.-""left"' 3 "Cent." 4 `" "Cent.-""right"' 5 "Right", nogrid) ///
	xtitle(" ") yline(0, lp(shortdash) lc(cranberry) lwidth(vthin)) ///
	legend(off) ytitle("") title(" ") subtitle("Left-right self-placement" " ", size(12-pt)) scheme(s1mono) yla(, angle(h) nogrid) name(leftright, replace)
margins, dydx(year) over(leftright) pwcompare(effects)	

** generational cohort
mixed BSA c.year ib2.gener5 c.year#ib2.gener5 ///
	ib3.leftright c.year#ib3.leftright ///
	ib0.sex c.year#ib0.sex ///
	ib0.partisan c.year#ib0.partisan ///
	ib0.intr c.year#ib0.intr ///
if year >= 2012 || _all: R.land || _all: R.year, var

margins, dydx(year) over(gener5)
margins, dydx(year) at(gener5=(1(1)4))
marginsplot, plotop(msymbol(Oh) msize(medlarge) mc(edkblue) mlwidth(medium) lc(edkblue*.3) lwidth(thin) lp(longdash)) ciopts(lc(edkblue*.5) lwidth(medthin)) ///
	yla(, nogrid) xla(1 `" "Inter-""war" "' 2 `" "Baby""Boomer" "' 3 `" "Gen.""X" "' 4 "Mill.", nogrid) ///
	xtitle(" ") yline(0, lp(shortdash) lc(cranberry) lwidth(vthin)) ///
	legend(off) ytitle("") title (" ") subtitle("Generational cohort" " ", size(12-pt)) scheme(s1mono) yla(, angle(h) nogrid) plotregion(margin(l=5 r=5))  name(gener, replace)
margins, dydx(year) at(gener5=(1(1)4)) pwcompare(effects)

** sex
mixed BSA c.year ib0.sex c.year#ib0.sex ///
	ib3.leftright c.year#ib3.leftright ///
	ib2.gener5 c.year#ib2.gener5 ///
	ib0.partisan c.year#ib0.partisan ///
	ib0.intr c.year#ib0.intr ///
if year >= 2012 || _all: R.land || _all: R.year, var

margins, dydx(year) over(sex)
marginsplot, plotop(msymbol(Oh) msize(medlarge) mc(edkblue) mlwidth(medium) lc(edkblue*.3) lwidth(thin) lp(longdash)) ciopts(lc(edkblue*.5) lwidth(medthin)) ///
	yla(, nogrid) xla(0 `" "Male"" " "' 1 `" "Female"" " "', nogrid) ///
	xtitle(" ") yline(0, lc(cranberry) lp(shortdash) lwidth(vthin)) ///
	legend(off) ytitle("") title (" ") subtitle("Sex" " ", size(12-pt)) scheme(s1mono) yla(, angle(h) nogrid) plotregion(margin(l=5 r=5)) name(sex, replace)
margins, dydx(year) over(sex) pwcompare(effects)	

** partisanship
mixed BSA c.year ib0.partisan c.year#ib0.partisan ///
	ib3.leftright c.year#ib3.leftright ///
	ib2.gener5 c.year#ib2.gener5 ///
	ib0.sex c.year#ib0.sex ///
	ib0.intr c.year#ib0.intr ///
if year >= 2012 || _all: R.land || _all: R.year, var

margins, dydx(year) over(partisan)
marginsplot, plotop(msymbol(Oh) msize(medlarge) mc(edkblue) mlwidth(medium) lc(edkblue*.3) lwidth(thin) lp(longdash)) ciopts(lc(edkblue*.5) lwidth(medthin)) ///
	yla(, nogrid) xla(0 `" "Non-""partisan" "' 1 "Partisan", nogrid) ///
	xtitle(" ") yline(0, lc(cranberry) lp(shortdash) lwidth(vthin)) ///
	legend(off) ytitle("") title (" ") subtitle("Partisanship" " ", size(12-pt)) scheme(s1mono) yla(, angle(h) nogrid) plotregion(margin(l=5 r=5)) name(partisan, replace)
margins, dydx(year) over(partisan) pwcompare(effects)

** political interest
mixed BSA c.year ib0.intr c.year#ib0.intr ///
	ib3.leftright c.year#ib3.leftright ///
	ib2.gener5 c.year#ib2.gener5 ///
	ib0.sex c.year#ib0.sex ///
	ib0.partisan c.year#ib0.partisan ///
if year >= 2012 || _all: R.land || _all: R.year, var

margins, dydx(year) over(intr)
marginsplot, plotop(msymbol(Oh) msize(medlarge) mc(edkblue) mlwidth(medium) lc(edkblue*.3) lwidth(thin) lp(longdash)) ciopts(lc(edkblue*.5) lwidth(medthin)) ///
	yla(, nogrid) xla(0 `" "Not at""all" "' 1 "Hardly" 2 "Quite"  3 "Very", nogrid) ///
	xtitle(" ") yline(0, lp(shortdash) lc(cranberry) lwidth(vthin)) ///
	legend(off) ytitle("") title (" ") subtitle("Political interest" " ", size(12-pt)) scheme(s1mono) yla(, angle(h) nogrid) plotregion(margin(l=5 r=5)) name(intr, replace)
margins, dydx(year) over(intr) pwcompare(effects)

** Figure 4
gr combine leftright gener sex partisan intr, ycommon

// Belief System A and B (2016, 2020, and 2022; Figure 5)

		* adjust labels for graphs
		lab define leftright 1 "Left" 2 `" "Cent.-""left" "' 3 "Cent." 4 `" "Cent.-""right" "' 5 "Right", modify
		lab define gener5 1 `" "Inter-""war" "' 2 `" "Baby""Boomer" "' 3 `" "Gen.""X" "' 4 "Mill." 5 `" "Gen.""Z" "', modify
		lab define sex 0 `" "Male"" " "' 1 `" "Female"" " "', modify
		lab define partisan 0 `" "Non-""partisan" "' 1 "Partisan", modify
		lab define intr 0 `" "Not at""all" "' 1 "Hardly" 2 "Quite"  3 "Very", modify

mixed BSA c.year ib3.leftright c.year#ib3.leftright ///
	ib2.gener5 c.year#ib2.gener5 ///
	ib0.sex c.year#ib0.sex ///
	ib0.partisan c.year#ib0.partisan ///
	ib0.intr c.year#ib0.intr ///
if inlist(year,2016,2020,2022) || _all: R.land || _all: R.year, var
tab land if e(sample)

	** left-right
	margins, dydx(year) over(leftright) pwcompare(effects)
	margins, dydx(year) over(leftright) post
	estimates store leftrightA
	
	qui: mixed BSA c.year ib2.gener5 c.year#ib2.gener5 ///
		ib3.leftright c.year#ib3.leftright ///
		ib0.sex c.year#ib0.sex ///
		ib0.partisan c.year#ib0.partisan ///
		ib0.intr c.year#ib0.intr ///
	if inlist(year,2016,2020,2022) || _all: R.land || _all: R.year, var
	** generational cohort
	margins, dydx(year) at(gener5=(1(1)4)) pwcompare(effects)
	margins, dydx(year) over(gener5) post
	estimates store generA
		
	qui: mixed BSA c.year ib0.sex c.year#ib0.sex ///
		ib3.leftright c.year#ib3.leftright ///
		ib2.gener5 c.year#ib2.gener5 ///
		ib0.partisan c.year#ib0.partisan ///
		ib0.intr c.year#ib0.intr ///
	if inlist(year,2016,2020,2022) || _all: R.land || _all: R.year, var
	** sex
	margins, dydx(year) over(sex) pwcompare(effects)
	margins, dydx(year) over(sex) post
	estimates store sexA
	
	qui: mixed BSA c.year ib0.partisan c.year#ib0.partisan ///
		ib3.leftright c.year#ib3.leftright ///
		ib2.gener5 c.year#ib2.gener5 ///
		ib0.sex c.year#ib0.sex ///
		ib0.intr c.year#ib0.intr ///
	if inlist(year,2016,2020,2022) || _all: R.land || _all: R.year, var
	** partisanship
	margins, dydx(year) over(partisan) pwcompare(effects)
	margins, dydx(year) over(partisan) post
	estimates store partisanA
	
	qui: mixed BSA c.year ib0.intr c.year#ib0.intr ///
		ib3.leftright c.year#ib3.leftright ///
		ib2.gener5 c.year#ib2.gener5 ///
		ib0.sex c.year#ib0.sex ///
		ib0.partisan c.year#ib0.partisan ///
	if inlist(year,2016,2020,2022) || _all: R.land || _all: R.year, var
	** political interest
	margins, dydx(year) over(intr) pwcompare(effects)
	margins, dydx(year) over(intr) post
	estimates store intrA
	
mixed BSB c.year ib3.leftright c.year#ib3.leftright ///
	ib2.gener5 c.year#ib2.gener5 ///
	ib0.sex c.year#ib0.sex ///
	ib0.partisan c.year#ib0.partisan ///
	ib0.intr c.year#ib0.intr ///
|| _all: R.land || _all: R.year, var
tab land if e(sample)

	** left-right
	margins, dydx(year) over(leftright) pwcompare(effects)
	margins, dydx(year) over(leftright) post
	estimates store leftrightB
	
	qui: mixed BSB c.year ib2.gener5 c.year#ib2.gener5 ///
		ib3.leftright c.year#ib3.leftright ///
		ib0.sex c.year#ib0.sex ///
		ib0.partisan c.year#ib0.partisan ///
		ib0.intr c.year#ib0.intr ///
	|| _all: R.land || _all: R.year, var
	** generational cohort
	margins, dydx(year) at(gener5=(1(1)4)) pwcompare(effects)
	margins, dydx(year) over(gener5) post
	estimates store generB
			
	qui: mixed BSB c.year ib0.sex c.year#ib0.sex ///
		ib3.leftright c.year#ib3.leftright ///
		ib2.gener5 c.year#ib2.gener5 ///
		ib0.partisan c.year#ib0.partisan ///
		ib0.intr c.year#ib0.intr ///
	|| _all: R.land || _all: R.year, var
	** sex
	margins, dydx(year) over(sex) pwcompare(effects)
	margins, dydx(year) over(sex) post
	estimates store sexB
			
	qui: mixed BSB c.year ib0.partisan c.year#ib0.partisan ///
		ib3.leftright c.year#ib3.leftright ///
		ib2.gener5 c.year#ib2.gener5 ///
		ib0.sex c.year#ib0.sex ///
		ib0.intr c.year#ib0.intr ///
	|| _all: R.land || _all: R.year, var
	** partisanship
	margins, dydx(year) over(partisan) pwcompare(effects)
	margins, dydx(year) over(partisan) post
	estimates store partisanB

	qui: mixed BSB c.year ib0.intr c.year#ib0.intr ///
		ib3.leftright c.year#ib3.leftright ///
		ib2.gener5 c.year#ib2.gener5 ///
		ib0.sex c.year#ib0.sex ///
		ib0.partisan c.year#ib0.partisan ///
	|| _all: R.land || _all: R.year, var
	** political interest
	margins, dydx(year) over(intr) pwcompare(effects)
	margins, dydx(year) over(intr) post
	estimates store intrB
	
	coefplot (leftrightA, msymbol(Oh) msize(medlarge) mc(edkblue) mlwidth(medium) ciopts(recast(rcap) lc(edkblue*.5) lwidth(medthin)) label(Belief System {it:A})) ///
		(leftrightB, msymbol(S) msize(medlarge) mc(edkblue) ciopts(recast(rcap) lc(edkblue*.5) lwidth(medthin)) label(Belief System {it:B})), ///
		vertical yline(0, lp(shortdash) lc(cranberry) lwidth(vthin)) yla(, angle(h) nogrid) scheme(s1color) ///
		legend(rows(1) pos(6) region(lcolor(none))) subtitle("Left-right self-placement" " ", size(12-pt))  name(leftrightAB, replace)

	coefplot (generA, msymbol(Oh) msize(medlarge) mc(edkblue) mlwidth(medium) ciopts(recast(rcap) lc(edkblue*.5) lwidth(medthin)) label(Belief System {it:A})) ///
		(generB, msymbol(S) msize(medlarge) mc(edkblue) ciopts(recast(rcap) lc(edkblue*.5) lwidth(medthin)) label(Belief System {it:B})), ///
		order(1.gener5 2.gener5 3.gener5 4.gener5) ///
		vertical yline(0, lp(shortdash) lc(cranberry) lwidth(vthin)) yla(, angle(h) nogrid) scheme(s1color) ///
		legend(rows(1) pos(6) region(lcolor(none))) subtitle("Generational cohort" " ", size(12-pt)) name(generAB, replace)

	coefplot (sexA, msymbol(Oh) msize(medlarge) mc(edkblue) mlwidth(medium) ciopts(recast(rcap) lc(edkblue*.5) lwidth(medthin)) label(Belief System {it:A})) ///
		(sexB, msymbol(S) msize(medlarge) mc(edkblue) ciopts(recast(rcap) lc(edkblue*.5) lwidth(medthin)) label(Belief System {it:B})), ///
		vertical yline(0, lp(shortdash) lc(cranberry) lwidth(vthin)) yla(, angle(h) nogrid) scheme(s1color) ///
		legend(rows(1) pos(6) region(lcolor(none))) subtitle("Sex" " ", size(12-pt))  name(sexAB, replace)

	coefplot (partisanA, msymbol(Oh) msize(medlarge) mc(edkblue) mlwidth(medium) ciopts(recast(rcap) lc(edkblue*.5) lwidth(medthin)) label(Belief System {it:A})) ///
		(partisanB, msymbol(S) msize(medlarge) mc(edkblue) ciopts(recast(rcap) lc(edkblue*.5) lwidth(medthin)) label(Belief System {it:B})), ///
		vertical yline(0, lp(shortdash) lc(cranberry) lwidth(vthin)) yla(, angle(h) nogrid) scheme(s1color) ///
		legend(rows(1) pos(6) region(lcolor(none))) subtitle("Partisanship" " ", size(12-pt))  name(partAB, replace)

	coefplot (intrA, msymbol(Oh) msize(medlarge) mc(edkblue) mlwidth(medium) ciopts(recast(rcap) lc(edkblue*.5) lwidth(medthin)) label(Belief System {it:A})) ///
		(intrB, msymbol(S) msize(medlarge) mc(edkblue) ciopts(recast(rcap) lc(edkblue*.5) lwidth(medthin)) label(Belief System {it:B})), ///
		vertical yline(0, lp(shortdash) lc(cranberry) lwidth(vthin)) yla(, angle(h) nogrid) scheme(s1color) ///
		legend(rows(1) pos(6) region(lcolor(none))) subtitle("Political interest" " ", size(12-pt)) name(intrAB, replace)

** Figure 5
grc1leg leftrightAB generAB sexAB partAB intrAB, ycommon

		// APPENDIX
		lab define leftright 1 "Left" 2 "Center-left" 3 "Center" 4 "Center-right" 5 "Right", modify
		lab define gener5 1 "Interwar" 2 "Baby Boomer" 3 "Generation X" 4 "Millennials" 5 "Generation Z", modify
		lab define sex 0 "Male" 1 "Female", modify
		lab define partisan 0 "Non-partisan" 1 "Partisan", modify
		lab define intr 0 "Not at all interested" 1 "Hardly interested" 2 "Quite interested"  3 "Very interested", modify

		eststo modelAa: mixed BSA c.year ib3.leftright c.year#ib3.leftright ///
			ib2.gener5 c.year#ib2.gener5 ///
			ib0.sex c.year#ib0.sex ///
			ib0.partisan c.year#ib0.partisan ///
			ib0.intr c.year#ib0.intr ///
		if year >= 2012 || _all: R.land || _all: R.year, var

		** Figure A4a
		qui margins leftright, at(year=(2012 2022))
		mplotoffset, off(.5) ytitle("") xtitle("") title("") ylab(, nogrid labsize(medium)) xlab(, nogrid labsize(medium)) yscale(lstyle(none)) ///
			xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall)) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8)) ///
			plot3opts(msymbol(Dh) msize(large) mcolor(edkblue*.6) mlwidth(thin) lcolor(edkblue*.6) lwidth(thin)) ci3opts(lwidth(thin) lcolor(edkblue*.6)) ///
			plot4opts(msymbol(X) msize(large) mcolor(edkblue*.4) mlwidth(thin) lcolor(edkblue*.4) lwidth(thin)) ci4opts(lwidth(thin) lcolor(edkblue*.4)) ///
			plot5opts(msymbol(Oh) msize(large) mcolor(edkblue*.2) mlwidth(thin) lcolor(edkblue*.2) lwidth(thin)) ci5opts(lwidth(thin) lcolor(edkblue*.2))
		margins leftright, at(year=(2012 2022)) pwcompare(effects)

		** Figure A4b
		mixed BSA c.year ib3.leftright c.year#ib3.leftright ///
			ib2.gener5 c.year#ib2.gener5 ///
			ib0.sex c.year#ib0.sex ///
			ib0.partisan c.year#ib0.partisan ///
			ib0.intr c.year#ib0.intr ///
		if year >= 2012 || _all: R.land || _all: R.year, var
		qui margins gener5, at(year=(2012 2022))
		mplotoffset,  off(.5) ytitle("") xtitle("") title("") ylab(, nogrid labsize(medium)) xlab(, nogrid labsize(medium)) ///
			yscale(lstyle(none)) xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall) ///
				order(6 "Interwar" 7 "Baby Boomer" 8 "Generation X" 9 "Millennials" 10 "Generation Z")) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8)) ///
			plot3opts(msymbol(Dh) msize(large) mcolor(edkblue*.6) mlwidth(thin) lcolor(edkblue*.6) lwidth(thin)) ci3opts(lwidth(thin) lcolor(edkblue*.6)) ///
			plot4opts(msymbol(X) msize(large) mcolor(edkblue*.4) mlwidth(thin) lcolor(edkblue*.4) lwidth(thin)) ci4opts(lwidth(thin) lcolor(edkblue*.4))
		margins gener5, at(year=(2012 2022)) pwcompare(effects)

		** Figure A4c
		qui margins sex, at(year=(2012 2022))
		mplotoffset,  off(.5) ytitle("") xtitle("") title("") ylab(, nogrid labsize(medium)) xlab(, nogrid labsize(medium)) yscale(lstyle(none)) ///
			xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall)) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8))
		margins sex, at(year=(2012 2022)) pwcompare(effects)

		** Figure A4d
		qui margins partisan, at(year=(2012 2022))
		mplotoffset, off(.5) ytitle("") xtitle("") title("") ylab(, nogrid labsize(medium)) xlab(, nogrid labsize(medium)) yscale(lstyle(none)) ///
			xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall)) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8))
		margins partisan, at(year=(2012 2022)) pwcompare(effects)

		** Figure A4e
		qui margins intr, at(year=(2012 2022))
		mplotoffset, off(.5) ytitle("") xtitle("") title("") ylab(, angle(h) nogrid labsize(medium)) xlab(, nogrid labsize(medium)) yscale(lstyle(none)) ///
			xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall)) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8)) ///
			plot3opts(msymbol(Dh) msize(large) mcolor(edkblue*.6) mlwidth(thin) lcolor(edkblue*.6) lwidth(thin)) ci3opts(lwidth(thin) lcolor(edkblue*.6)) ///
			plot4opts(msymbol(X) msize(large) mcolor(edkblue*.4) mlwidth(thin) lcolor(edkblue*.4) lwidth(thin)) ci4opts(lwidth(thin) lcolor(edkblue*.4))
		margins intr, at(year=(2012 2022)) pwcompare(effects)

		** B-1) Figures A5a-e, Panel A: Belief System A
		eststo modelAb: mixed BSA c.year ib3.leftright c.year#ib3.leftright ///
			ib2.gener5 c.year#ib2.gener5 ///
			ib0.sex c.year#ib0.sex ///
			ib0.partisan c.year#ib0.partisan ///
			ib0.intr c.year#ib0.intr ///
		if inlist(year,2016,2020,2022) || _all: R.land || _all: R.year, var

		** left-right
		qui margins leftright, at(year=(2016 2022))
		mplotoffset, off(.5) ytitle("") xtitle("") title("Belief System {it:A}" " ", size(medlarge)) ///
			ylab(, angle(h) nogrid labsize(medium)) xlab(, nogrid labsize(medium)) yscale(lstyle(none)) ///
			xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall)) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8)) ///
			plot3opts(msymbol(Dh) msize(large) mcolor(edkblue*.6) mlwidth(thin) lcolor(edkblue*.6) lwidth(thin)) ci3opts(lwidth(thin) lcolor(edkblue*.6)) ///
			plot4opts(msymbol(X) msize(large) mcolor(edkblue*.4) mlwidth(thin) lcolor(edkblue*.4) lwidth(thin)) ci4opts(lwidth(thin) lcolor(edkblue*.4)) ///
			plot5opts(msymbol(Oh) msize(large) mcolor(edkblue*.2) mlwidth(thin) lcolor(edkblue*.2) lwidth(thin)) ci5opts(lwidth(thin) lcolor(edkblue*.2)) ///
			name(Ab_leftright, replace)
		margins leftright, at(year=(2016 2022)) pwcompare(effects)
		** generational cohort
		qui margins gener5, at(year=(2016 2022))
		mplotoffset,  off(.5) ytitle("") xtitle("") title("Belief System {it:A}" " ", size(medlarge)) ///
			ylab(, nogrid labsize(medium)) xlab(, nogrid labsize(medium)) ///
			yscale(lstyle(none)) xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall) ///
			order(7 "Baby Boomer" 8 "Generation X" 9 "Millennials" 10 "Generation Z")) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8)) ///
			plot3opts(msymbol(Dh) msize(large) mcolor(edkblue*.6) mlwidth(thin) lcolor(edkblue*.6) lwidth(thin)) ci3opts(lwidth(thin) lcolor(edkblue*.6)) ///
			plot4opts(msymbol(X) msize(large) mcolor(edkblue*.4) mlwidth(thin) lcolor(edkblue*.4) lwidth(thin)) ci4opts(lwidth(thin) lcolor(edkblue*.4)) ///
			plot5opts(msymbol(Oh) msize(large) mcolor(edkblue*.2) mlwidth(thin) lcolor(edkblue*.2) lwidth(thin)) ci5opts(lwidth(thin) lcolor(edkblue*.2)) ///
			name(Ab_gener, replace)
		margins gener5, at(year=(2016 2022)) pwcompare(effects)
		** sex
		qui margins sex, at(year=(2016 2022))
		mplotoffset,  off(.5) ytitle("") xtitle("") title("Belief System {it:A}" " ", size(medlarge)) ///
			ylab(, angle(h) nogrid labsize(medium)) xlab(, nogrid labsize(medium)) yscale(lstyle(none)) ///
			xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall)) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8)) ///
			name(Ab_sex, replace)
		margins sex, at(year=(2016 2022)) pwcompare(effects)
		** partisan
		qui margins partisan, at(year=(2016 2022))
		mplotoffset, off(.5) ytitle("") xtitle("") title("Belief System {it:A}" " ", size(medlarge)) ///
			ylab(, angle(h) nogrid labsize(medium)) xlab(, nogrid labsize(medium)) yscale(lstyle(none)) ///
			xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall)) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8)) ///
			name(Ab_partisan, replace)
		margins partisan, at(year=(2016 2022)) pwcompare(effects)
		** political interest
		qui margins intr, at(year=(2016 2022))
		mplotoffset, off(.5) ytitle("") xtitle("") title("Belief System {it:A}" " ", size(medlarge)) ///
			ylab(, angle(h) nogrid labsize(medium)) xlab(, nogrid labsize(medium)) yscale(lstyle(none)) ///
			xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall)) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8)) ///
			plot3opts(msymbol(Dh) msize(large) mcolor(edkblue*.6) mlwidth(thin) lcolor(edkblue*.6) lwidth(thin)) ci3opts(lwidth(thin) lcolor(edkblue*.6)) ///
			plot4opts(msymbol(X) msize(large) mcolor(edkblue*.4) mlwidth(thin) lcolor(edkblue*.4) lwidth(thin)) ci4opts(lwidth(thin) lcolor(edkblue*.4)) ///
			name(Ab_intr, replace)
		margins intr, at(year=(2016 2022)) pwcompare(effects)

		** B-2) Figures A5a-e, Panel B: Belief System B
		eststo modelB: mixed BSB c.year ib3.leftright c.year#ib3.leftright ///
			ib2.gener5 c.year#ib2.gener5 ///
			ib0.sex c.year#ib0.sex ///
			ib0.partisan c.year#ib0.partisan ///
			ib0.intr c.year#ib0.intr ///
		|| _all: R.land || _all: R.year, var

		** left-right
		qui margins leftright, at(year=(2016 2022))
		mplotoffset, off(.5) ytitle("") xtitle("") title("Belief System {it:B}" " ", size(medlarge)) ///
			ylab(, angle(h) nogrid labsize(medium)) xlab(, nogrid labsize(medium)) yscale(lstyle(none)) ///
			xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall)) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8)) ///
			plot3opts(msymbol(Dh) msize(large) mcolor(edkblue*.6) mlwidth(thin) lcolor(edkblue*.6) lwidth(thin)) ci3opts(lwidth(thin) lcolor(edkblue*.6)) ///
			plot4opts(msymbol(X) msize(large) mcolor(edkblue*.4) mlwidth(thin) lcolor(edkblue*.4) lwidth(thin)) ci4opts(lwidth(thin) lcolor(edkblue*.4)) ///
			plot5opts(msymbol(Oh) msize(large) mcolor(edkblue*.2) mlwidth(thin) lcolor(edkblue*.2) lwidth(thin)) ci5opts(lwidth(thin) lcolor(edkblue*.2)) ///
			name(B_leftright, replace)
		margins leftright, at(year=(2016 2022)) pwcompare(effects)
		** generational cohort
		qui margins gener5, at(year=(2016 2022))
		mplotoffset,  off(.5) ytitle("") xtitle("") title("Belief System {it:B}" " ", size(medlarge)) ///
			ylab(, nogrid labsize(medium)) xlab(, nogrid labsize(medium)) ///
			yscale(lstyle(none)) xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall) ///
				order(8 "Generation X" 9 "Millennials")) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8)) ///
			plot3opts(msymbol(Dh) msize(large) mcolor(edkblue*.6) mlwidth(thin) lcolor(edkblue*.6) lwidth(thin)) ci3opts(lwidth(thin) lcolor(edkblue*.6)) ///
			plot4opts(msymbol(X) msize(large) mcolor(edkblue*.4) mlwidth(thin) lcolor(edkblue*.4) lwidth(thin)) ci4opts(lwidth(thin) lcolor(edkblue*.4)) ///
			plot5opts(msymbol(Oh) msize(large) mcolor(edkblue*.2) mlwidth(thin) lcolor(edkblue*.2) lwidth(thin)) ci5opts(lwidth(thin) lcolor(edkblue*.2)) ///
			name(B_gener, replace)
		margins gener5, at(year=(2016 2022)) pwcompare(effects)
		** sex
		qui margins sex, at(year=(2016 2022))
		mplotoffset,  off(.5) ytitle("") xtitle("") title("Belief System {it:B}" " ", size(medlarge)) ///
			ylab(, angle(h) nogrid labsize(medium)) xlab(, nogrid labsize(medium)) yscale(lstyle(none)) ///
			xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall)) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8)) ///
			name(B_sex, replace)
		margins sex, at(year=(2016 2022)) pwcompare(effects)
		** partisan
		qui margins partisan, at(year=(2016 2022))
		mplotoffset, off(.5) ytitle("") xtitle("") title("Belief System {it:B}" " ", size(medlarge)) ///
			ylab(, angle(h) nogrid labsize(medium)) xlab(, nogrid labsize(medium)) yscale(lstyle(none)) ///
			xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall)) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8)) ///
			name(B_partisan, replace)
		margins partisan, at(year=(2016 2022)) pwcompare(effects)
		** political interest
		qui margins intr, at(year=(2016 2022))
		mplotoffset, off(.5) ytitle("") xtitle("") title("Belief System {it:B}" " ", size(medlarge)) ///
			ylab(, angle(h) nogrid labsize(medium)) xlab(, nogrid labsize(medium)) yscale(lstyle(none)) ///
			xscale(lstyle(none)) plotregion(margin(l=10 r=10) lc(black)) legend(pos(6) stack rows(1) symplacement(center) size(medsmall)) ///
			plot1opts(msymbol(Th) msize(large) mcolor(edkblue) mlwidth(thin) lcolor(edkblue) lwidth(thin)) ci1opts(lwidth(thin) lcolor(edkblue)) ///
			plot2opts(msymbol(Sh) msize(large) mcolor(edkblue*.8) mlwidth(thin) lcolor(edkblue*.8) lwidth(thin)) ci2opts(lwidth(thin) lcolor(edkblue*.8)) ///
			plot3opts(msymbol(Dh) msize(large) mcolor(edkblue*.6) mlwidth(thin) lcolor(edkblue*.6) lwidth(thin)) ci3opts(lwidth(thin) lcolor(edkblue*.6)) ///
			plot4opts(msymbol(X) msize(large) mcolor(edkblue*.4) mlwidth(thin) lcolor(edkblue*.4) lwidth(thin)) ci4opts(lwidth(thin) lcolor(edkblue*.4)) ///
			name(B_intr, replace)
		margins intr, at(year=(2016 2022)) pwcompare(effects)

		** Figure A5a
		grc1leg Ab_leftright B_leftright, ycommon

		** Figure A5b
		grc1leg Ab_gener B_gener, ycommon

		** Figure A5c
		grc1leg Ab_sex B_sex, ycommon

		** Figure A5d
		grc1leg Ab_partisan B_partisan, ycommon

		** Figure A5e
		grc1leg Ab_intr B_intr, ycommon

		
		** C) Table A3
		esttab modelAa modelAb modelB using "~\a.rtf", ///
			replace se label star(+ .10 * .05 ** .01 *** .001) b(3) se(3)

		**no estimates for Gen. Z
		bysort gener5: tab year if inrange(year,2012,2022) & leftright == 3 & sex == 0 & partisan == 0 & intr == 0 & !missing(BSA)
		bysort gener5: tab year if inlist(year,2016,2020,2022) & leftright == 3 & sex == 0 & partisan == 0 & intr == 0 & !missing(BSB)

		 eststo modelAa_gener4: mixed BSA_gener4 c.year ib3.leftright c.year#ib3.leftright ///
			ib2.gener4 c.year#ib2.gener4 ///
			ib0.sex c.year#ib0.sex ///
			ib0.partisan c.year#ib0.partisan ///
			ib0.intr c.year#ib0.intr ///
		if year >= 2012 || _all: R.land || _all: R.year, var
		tab land if e(sample)

		 eststo modelAb_gener4: mixed BSA_gener4 c.year ib3.leftright c.year#ib3.leftright ///
			ib2.gener4 c.year#ib2.gener4 ///
			ib0.sex c.year#ib0.sex ///
			ib0.partisan c.year#ib0.partisan ///
			ib0.intr c.year#ib0.intr ///
		if inlist(year,2016,2020,2022) || _all: R.land || _all: R.year, var

		 eststo modelB_gener4: mixed BSB_gener4 c.year ib3.leftright c.year#ib3.leftright ///
			ib2.gener4 c.year#ib2.gener4 ///
			ib0.sex c.year#ib0.sex ///
			ib0.partisan c.year#ib0.partisan ///
			ib0.intr c.year#ib0.intr ///
		|| _all: R.land || _all: R.year, var

		esttab modelAa modelAa_gener4 modelAb modelAb_gener4 modelB modelB_gener4 using "~\b.rtf", ///
			replace se label star(+ .10 * .05 ** .01 *** .001) b(3) se(3)